package com.shujia.mr.youhua;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WeatherMapper extends Mapper<LongWritable, Text, Text, LongWritable> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context) throws IOException, InterruptedException {
        //2022-10-16 22:23:10	-4
        String line = value.toString();
        String[] split = line.split("\t");
        String yMd = split[0]; // 2022-10-16 22:23:10
        String temp = split[1]; // -4
        String month = yMd.substring(5, 7);
        String year = yMd.substring(0, 4);
        if("02".equals(month)){
            context.write(new Text(year+"-"+month),new LongWritable(Long.parseLong(temp)));
        }
    }
}
